package com.niuxiaofa.newlaw.adapter;

import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Bean.NewListBean;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.GlideUtils;
import com.niuxiaofa.newlaw.Tools.UIUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class ConsultationKindAdapter extends RecyclerView.Adapter<ConsultationKindAdapter.ViewHolder> {
    public List<NewListBean.DataDTO> listEntities;
    SharedPreferences sharedPreferences;
    Onclick onclick;



    public ConsultationKindAdapter(List<NewListBean.DataDTO> newsList, Onclick onclick) {
        this.onclick = onclick;
        this.listEntities = newsList;
    }


    @Override
    public ViewHolder onCreateViewHolder( ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_news, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder( ViewHolder viewHolder, int i) {

        NewListBean.DataDTO listEntity = listEntities.get(i);

        GlideUtils.loadRoundedImage(UIUtils.getContext(), listEntity.getNewsPicUrl(), viewHolder.newsPic);

        viewHolder.time.setText(listEntity.getCreatTime());

        viewHolder.newsPic.setOnClickListener(e -> {
            onclick.onclick(i);
        });



    }

    @Override
    public int getItemCount() {
        return listEntities.size();
    }

    public interface Onclick {

        void onclick(int c);

    }

    static class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.newsPic)
        ImageView newsPic;

        @BindView(R.id.newsTitle)
        TextView newsTitle;

        @BindView(R.id.time)
        TextView time;



        public ViewHolder( View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
